package com.ruoyi.collect.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.collect.domain.Works;
import com.ruoyi.collect.mapper.WorksMapper;
import com.ruoyi.collect.service.IWorksService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 上传作品Service业务层处理
 * 
 * @author lpt
 * @date 2025-08-16
 */
@Service("collectWorksServiceImpl")
public class WorksServiceImpl implements IWorksService
{
    @Autowired
    private WorksMapper worksMapper;

    /**
     * 查询上传作品
     * 
     * @param workId 上传作品主键
     * @return 上传作品
     */
    @Override
    public Works selectWorksByWorkId(Integer workId)
    {
        return worksMapper.selectWorksByWorkId(workId);
    }

    /**
     * 查询上传作品列表
     * 
     * @param works 上传作品
     * @return 上传作品
     */
    @Override
    public List<Works> selectWorksList(Works works)
    {
        return worksMapper.selectWorksList(works);
    }

    /**
     * 新增上传作品
     * 
     * @param works 上传作品
     * @return 结果
     */
    @Override
    public int insertWorks(Works works)
    {
        works.setCreateTime(DateUtils.getNowDate());
        return worksMapper.insertWorks(works);
    }

    /**
     * 修改上传作品
     * 
     * @param works 上传作品
     * @return 结果
     */
    @Override
    public int updateWorks(Works works)
    {
        return worksMapper.updateWorks(works);
    }

    /**
     * 批量删除上传作品
     * 
     * @param workIds 需要删除的上传作品主键
     * @return 结果
     */
    @Override
    public int deleteWorksByWorkIds(Integer[] workIds)
    {
        return worksMapper.deleteWorksByWorkIds(workIds);
    }

    /**
     * 删除上传作品信息
     * 
     * @param workId 上传作品主键
     * @return 结果
     */
    @Override
    public int deleteWorksByWorkId(Integer workId)
    {
        return worksMapper.deleteWorksByWorkId(workId);
    }



    //--------------------------------------------------------------------------


    @Override
    public Map<String, Object> findByPage(Integer pageNum, Integer pageSize, Works works) {
        PageHelper.startPage(pageNum,pageSize);
        List<Works> list = worksMapper.select(works);
        PageInfo<Works> pageInfo = new PageInfo<>(list);
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put("total", pageInfo.getTotal());
        pageMap.put("pages", pageInfo.getPages());
        pageMap.put("list", pageInfo.getList());
        return pageMap;
    }

    @Override
    public Works findById(Integer id) {
        return worksMapper.selectWorksById(id);
    }

    @Override
    public List<Works> findBatch() {
        return worksMapper.select(null);
    }

    @Override
    public int remove(Integer id) {
        return worksMapper.deleteById(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return worksMapper.deleteBatch(ids);
    }

    @Override
    public int addid(Works domain) {
        return worksMapper.insert(domain);
    }

    @Override
    public int editid(Works domain) {
        return worksMapper.update(domain);
    }


}
